//
//  KVRetwetedStatusView.swift
//  KVBestMicroblog
//
//  Created by 李康卫 on 16/7/26.
//  Copyright © 2016年 李康卫. All rights reserved.
//

import UIKit

class KVRetwetedStatusView: UIView {
    ///转发的微博
    var retweetedStatus: KVStatuses? {
        didSet {
//            let userName: String = (retweetedStatus?.user?.screen_name)!
//            let text: String = (retweetedStatus?.text)!
//            
            
            retweetedLabel.text = retweetedStatus?.content
            
            //设置图片, 先判断有没有图片
            let pic_URLs = retweetedStatus?.pictureURLs
            if pic_URLs == nil {
                print("没有图片")
            } else {
//                print("有图片")
                retweetedPicturesView.pictureURLS = pic_URLs
            }
            
        }
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor(white: 237.0/255.0, alpha: 1)
        //添加子控件
        setupUI()
    }
    
    private func setupUI() {
        //添加控件到容器
        addSubview(retweetedLabel)
        addSubview(retweetedPicturesView)
        //添加约束
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self).offset(homeCellSpace)
            make.leading.equalTo(self).offset(homeCellSpace)
        }
        //添加转发图片的约束
        retweetedPicturesView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLabel.snp_bottom).offset(homeCellSpace)
            make.leading.equalTo(self).offset(homeCellSpace)
        }


        self.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(retweetedPicturesView.snp_bottom).offset(homeCellSpace)
        }
    }
    
    // MARK: - 懒加载控件
    private lazy var retweetedLabel: UILabel = {
        let retweetedLabel = UILabel()
        retweetedLabel.text = "解决约束冲突的代价"

        retweetedLabel.font = UIFont.systemFontOfSize(homeTextSize)
        
        retweetedLabel.textColor = UIColor.blackColor()
        retweetedLabel.numberOfLines = 0
        retweetedLabel.sizeToFit()
        
        retweetedLabel.preferredMaxLayoutWidth = UIScreen.width() - 2*homeCellSpace
        return retweetedLabel
    }()
    
    //添加转发图片
    private lazy var retweetedPicturesView: KVStatusPictureView = KVStatusPictureView()
}
